﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace _18miljard.TextLinks
{
	public class TextLink
	{
		string href;
		string text;
		string prefix;
		string suffix;
		string name;
		string email;
		bool nofollow;
		bool frontPageOnly;

		public TextLink(string href, string text, string prefix, string suffix, string name, string email, bool frontPageOnly)
			: this(href, text, prefix, suffix, name, email, frontPageOnly, false)
		{ }

		public TextLink(string href, string text, string prefix, string suffix, string name, string email, bool frontPageOnly, bool nofollow)
		{
			this.href = href;
			this.text = text;
			this.prefix = prefix;
			this.suffix = suffix;
			this.name = name;
			this.email = email;
			this.nofollow = nofollow;
			this.frontPageOnly = frontPageOnly;
		}

		public WebControl CreateWebControl()
		{
			Panel panel = new Panel();
			panel.CssClass = "sponsor";

			if (string.IsNullOrEmpty(this.prefix) == false)
			{
				Label prefix = new Label();
				prefix.Text = this.prefix;

				panel.Controls.Add(prefix);
			}

			HyperLink link = new HyperLink();
			link.Target = "_blank";
			link.NavigateUrl = this.href;
			link.Text = this.text;
			link.CssClass = "sponsor";

			if (this.nofollow)
			    link.Attributes["rel"] = "nofollow";
			
			panel.Controls.Add(link);

			if (string.IsNullOrEmpty(this.suffix) == false)
			{
				Label suffix = new Label();
				suffix.Text = this.suffix;

				panel.Controls.Add(suffix);
			}

			return panel;
		}
		
		public string Href
		{
			get { return this.href; }
		}

		public string Text
		{
			get { return this.text; }
		}

		public string Prefix
		{
			get { return this.prefix; }
		}

		public string Suffix
		{
			get { return this.suffix; }
		}

		public string Name
		{
			get { return this.name; }
		}

		public string Email
		{
			get { return this.email; }
		}

		public bool Nofollow
		{
			get { return this.nofollow; }
		}

		public bool FrontPageOnly
		{
			get { return this.frontPageOnly; }
		}
		 
	}
}
